<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>{{siteName}}-订单管理</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="{{ADMIN_DOMAIN}}static/layui/css/layui.css?version={{version}}" media="all">
  <link rel="stylesheet" href="{{ADMIN_DOMAIN}}static/style/admin.css?version={{version}}" media="all">
</head>
<body>
  <div class="layui-fluid">
    <div class="layui-card">
      <div class="layui-form layui-card-header layuiadmin-card-header-auto">
          <div class="layui-card-body">
            <div class="test-table-reload-btn" >
              <div class="layui-inline">
                <label class="layui-form-label">订单id</label>
                <div class="layui-input-inline">
                  <input class="layui-input" name="order_id" placeholder="请输入订单id" id="order_id" autocomplete="off">
                </div>
              </div>
              <div class="layui-inline">
                <label class="layui-form-label">状态</label>
                <div class="layui-input-inline">
                <select name="status" id="status">
                    <option value="99">请选择</option>
                    <option value="0">待支付</option>
                    <option value="1">支付成功</option>
                    <option value="2">支付失败</option>
                </select>
                </div>
              </div>
              <div class="layui-inline">
                <div class="layui-input-inline">
                  <button id="search" class="layui-btn layuiadmin-btn-comm" data-type="reload" lay-submit="" lay-filter="LAY-app-contcomm-search">
                  <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                  </button>
                </div>
              </div>
              
            </div>
            
          </div>
       
        </div>
     
    </div>
      <div class="layui-btn-container">
              <button class="layui-btn">昨日收益:￥{{y_count}}</button>
              <button class="layui-btn layui-btn-danger">今日收益：￥{{t_count}}</button>
      </div>

     
    <div class="layui-row">
      <div class="layui-col-md12">
        <div class="layui-card">
          <div class="layui-card-body">
           
            <table class="layui-hide" id="table_src" lay-filter="test"></table>
            {% verbatim %}
            <script type="text/html" id="test-table-switchTpl">
              <!-- 这里的 checked 的状态只是演示 -->
              <input type="checkbox" lay-filter="test-table-status" name="status" lay-skin="switch" lay-text="正常|禁用" 
               value="{{ d.status }}" data-json="{{ encodeURIComponent(JSON.stringify(d)) }}" {{ d.status == 1 ? 'checked' : '' }}>
            </script>
            {% endverbatim %}
          </div>
        </div>
      </div>
    </div>
  </div>
  <script type="text/html" id="role">
    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
  </script>
  <script src="{{ADMIN_DOMAIN}}static/layui/layui.js"></script>  
  <script>
    var _table = null; 
    layui.config({
      version: "{{version}}",
      base: '{{ADMIN_DOMAIN}}static/' //静态资源所在路径
    }).extend({
      index: 'lib/index' //主入口模块
    }).use(['index', 'form', 'table','content'],function(){
      var $ = layui.$
      ,admin = layui.admin
      ,element = layui.element
      ,form = layui.form,
      table = layui.table;
      form.render(null, 'component-form-element');
      table.render({
        elem: '#table_src'
        ,url:'{{getu("Order_Order/index" , "inajax=1")}}'
        ,title: '后台用户'
        ,toolbar: true
        ,defaultToolbar:['filter']
        ,cols: [[
          {field:'order_id', title:'订单id', width:200, minWidth: 60, sort: true},
          {field:'uid', title:'用户id', minWidth: 150},
          {field:'create_date', title:'添加时间', minWidth: 150, sort: true},
          {field:'money', title:'支付金额', minWidth: 150, sort: true},
          {field:'status', title:'状态', width:80, templet: function(res){
            if (res.status === '0') {
              return '<button class="layui-btn layui-btn-warm layui-btn-xs">待支付</button>';
            } else if (res.status === '1') {
              return '<button class="layui-btn layui-btn-normal layui-btn-xs">支付成功</button>';
            } else if(res.status === '2') {
              return '<button class="layui-btn layui-btn-danger layui-btn-xs">支付失败</button>' ;
            }else{
                return '未知';
            }
          }},
          {field:'rsync_success', title:'异步回调状态', width:180, templet: function(res){
            if (res.rsync_success === '0') {
              return '<button class="layui-btn layui-btn-warm layui-btn-xs">没有发送回调</button>';
            } else if (res.rsync_success === '1') {
              return '<button class="layui-btn layui-btn-normal layui-btn-xs">异步回调成功</button>';
            } else if(res.rsync_success === '2') {
              return '<button class="layui-btn layui-btn-danger layui-btn-xs">回调失败</button>' ;
            }else{
                return '未知';
            }
          }}
          //,{title:'操作', toolbar: '#role', minWidth:100, width:150}
        ]]
        ,id: 'tables_id'
        ,page: true
        ,limits: [10,20,30,40,50] // 每页展示条数
        ,limit: {{pageSize}} // 每页默认显示的数量;注意：需要和后台首次传递过来的条数相同
      });
    //监听状态操作
    /*form.on('switch(test-table-status)', function(obj){
      var json = JSON.parse(decodeURIComponent($(this).data('json')));
      layer.tips(this.value + ' ' + this.name + '：'+ obj.elem.checked, obj.othis);
      json = table.clearCacheKey(json);
      console.log(json); //当前行数据
    });*/
      // 操作功能
      table.on('tool(test)', function(obj){
        var data = obj.data;
        if(obj.event === 'edit'){
          addOrEdit(data.user_id)
        }else if (obj.event === 'del'){
          deleteUser(data.user_id)
        }
      });
      $('#search').click(function () {
        search();
      });
      
      $('#search_ipt').keydown(function (event) {
        if (event.keyCode === 13) {
          search();
        }
      });
    
      function search() {
        var $where = getWhere();
        table.reload('tables_id', {
          page: {
            curr: 1 //重新从第 1 页开始
          }
          ,where: $where
        });
      };
      function getWhere(){
          var $order_id = $('#order_id').val().trim();
          var $status = $('#status').val().trim();
          return {
              order_id: $order_id,
              status : $status
          };
      }
      // 添加权限或者编辑权限
      function addOrEdit(user_id){
        var title = '添加后台用户',
        _url = "{{getu('admin/userAdd')}}", // 权限数据请求地址
        flag = true; // 用于判断关闭按钮触发还是数据提交触发
        if (user_id > 0  ) {
          title = '修改后台用户';
          _url = "{{getu('admin/userEdit')}}?user_id="+user_id
        }
        _table = layer.open({
            type: 2
            ,title: title // 标题
            ,content: _url  // url
            ,maxmin: true // 是否可以全屏
            ,area: ['80%', '80%'] // 弹出层的宽/高
            ,end: function () { // 页面销毁后执行
              if (flag) { // 数据提交触发
                var $where = getWhere();
                table.reload('tables_id', {
                  where: $where
                });
              }
            }
            ,cancel: function () { // 右上角关闭按钮触发的回调
              flag = false;
            }
        });
      }
      function deleteUser(user_id){
        layer.confirm('是否删除用户id为:' + user_id + " 此操作不可恢复" , {
            btn: ['是','否'] //按钮
          }, function(){
            $.ajax({
              type:'POST',
              url: '{{getu("admin/userDel")}}',
              data: { user_id : user_id },
              dataType: 'JSON',
              success: function (res) {
                  layer.close(loading);
                  if( res['code'] != 1 ){
                    layer.msg(res['msg'] , {icon : 5 } )
                    return ;
                  }
                  var $success = layer.alert('删除成功', {}, function(){
                      layer.close($success);
                      table.reload('tables_id');
                  });
              },
              beforeSend: function(){
                loading = layer.load(0, {shade: [0.1,'#fff']})
              },
              error: function (){
                layer.close(loading)
                layer.msg("网络繁忙请稍后" , {icon : 5 } )
              }
            });
        });
      }
  });
  // 用于role_add或者role_edit页面调用;
  function closeAndLoadData(){ 
    layer.close(_table); // 销毁layer弹出层
  }
  
  </script>
</body>
</html>